package com.mxchip.livestarmobile.mobile.ui.call

import android.util.Log
import androidx.lifecycle.MutableLiveData
import io.reactivex.disposables.CompositeDisposable

object RoomRepository {

    private val compositeDisposable = CompositeDisposable()

    val avDevices = MutableLiveData<List<AVDevice>>(arrayListOf())

    private const val TAG = "RoomRepository"
    fun replaceAVDevice(device: List<AVDevice>) {
        Log.d(TAG, "replaceAVDevice: ")
        avDevices.postValue(device)
    }

    fun addAVDevice(device: AVDevice) {
        Log.d(TAG, "addAVDevice: $device")
        val list = avDevices.value
        if (list is ArrayList && !list.contains(device)) {
            list.add(device)
        }
        avDevices.value = list
    }

    fun removeAVDevice(uid: String) {
        Log.d(TAG, "removeAVDevice: ")
        val list = avDevices.value?.filter {
            uid != it.uid
        }
        avDevices.value = list
    }

    fun removeAVDevice(uid: String, deviceName: String) {
        Log.d(TAG, "removeAVDevice: uid: String, deviceName: String")
        val list = avDevices.value?.filterNot {
            uid == it.uid && deviceName == it.deviceName
        }
        avDevices.value = list
    }

    fun init() {

    }

    fun clear() {
        compositeDisposable.clear()
        replaceAVDevice(arrayListOf())
    }

}